package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.timesegment.FurnaceTypeCodeData;
import com.jinmdz.fmis.api.admin.model.timesegment.TimeSegmentSaveData;
import com.jinmdz.fmis.api.admin.service.TimeSegmentService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.timesegment.TimeSegmentListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 火化预约时间段维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-12 14:50
 */
@Api(description = "火化预约时间段维护信息相关接口")
@RestController()
@RequestMapping("/admin/time-segment")
public class TimeSegmentController extends BaseController {

    @Resource
    private TimeSegmentService timeSegmentService;

    /**
     * 按照火化炉类型加载火化预约时间段信息
     *
     * @param data 火化炉类型编码
     * @return
     * @author LiCongLu
     * @date 2020-03-13 14:52
     */
    @ApiOperation(value = "按照火化炉类型加载火化预约时间段信息", notes = "根据表【cremation_time_segment】中火化炉型编码【furnace_type_code】加载火化预约时间段分类【cremation_time_segment】表中所有有效火化预约时间段信息")
    @PostMapping("/load-time-segment-list-with-code")
    public BaseResult<ArrayList<TimeSegmentListItem>> loadTimeSegmentListWithCode(@RequestBody FurnaceTypeCodeData data) {
        return resultHandler(data, userItem -> timeSegmentService.loadTimeSegmentListWithCode(data));
    }

    /**
     * 保存火化预约时间段信息到cremation_time_segment表中
     *
     * @param data 火化预约时间段请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-13 14:52
     */
    @ApiOperation(value = "保存火化预约时间段信息到【cremation_time_segment】表中", notes = "保存火化预约时间段信息到【cremation_time_segment】表中")
    @PostMapping("/save-time-segment")
    public BaseResult saveTimeSegment(@RequestBody ArrayList<TimeSegmentSaveData> data) {
        return resultHandler(data, userItem -> timeSegmentService.saveTimeSegment(userItem, data));
    }

    /**
     * 从cremation_time_segment表中删除指定id的火化预约时间段信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-13 14:52
     */
    @ApiOperation(value = "从cremation_time_segment表中删除指定id的火化预约时间段信息记录", notes = "从cremation_time_segment表中删除指定id的火化预约时间段信息")
    @PostMapping("/delete-time-segment-with-id")
    public BaseResult deleteTimeSegmentWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> timeSegmentService.deleteTimeSegmentWithId(userItem, data));
    }
}
